<template>
    <button
        :type="type"
        :size="size"
        :plain="plain"
        :disabled="disabled"
        :loading="loading"
        :form-type="formType"
        :open-type="openType"
        :hover-class="hoverClass"
        :hover-start-time="hoverStartTime"
        :hover-stay-time="hoverStayTime"
        @click="link"
        @getuserinfo="getUserInfor">
        <slot></slot>
    </button>
	
</template>

<script>
	export default {
        name: 'Button',
        props: {
            delta: {
                type: Number,
                default: -1
            },
            url: {
                type: String
            },
            routerType: {
                type: String,
                default: "navigate"
            },
            type: {
                type: String,
                default: 'default'
            },
            size: {
                type: String,
                default: 'default'
            },
            plain: {
                type: Boolean,
                default: false,
            },
            disabled: {
                type: Boolean,
                default: false,
            },
            loading: {
                type: Boolean,
                default: false,
            },
            formType: {
                type: String
            },
            openType: {
                type: String
            },
            hoverClass: {
                type: String,
                default: "button-hover"
            },
            hoverStartTime: {
                type: Number,
                default: 20
            },
            hoverStayTime: {
                type: Number,
                default: 70
            },	

        },
		data() {
			return {
				s: ''
			};
		},
        methods: {
            link(){
                const value = this.routerType;
                const url = this.url;
                if(url || (value == 'navigateBack' && this.delta)){
                    switch (value){
                    	case "navigate":
                            uni.navigateTo({
                            	url: url
                            })
                    		break;
                        case "redirect":
                            uni.redirectTo({
                            	url: url
                            })
                        	break;
                        case "switchTab":
                            uni.switchTab({
                            	url: url
                            })
                        	break;
                        case "reLaunch":
                            uni.reLaunch({
                            	url: url
                            })
                        	break;
                        case "navigateBack":
                            uni.navigateBack({
                            	delta: this.delta
                            })
                        	break;
                    	default:
                            throw new Error('routerType参数传入错误')
                    		break;
                    }
                }
                this.$emit('click')
            },
            getUserInfor(e){
                this.$emit('getUserInfo', e)
            }
        }
	}
</script>

<style>

</style>
